package com.zhz.lib.project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhz.lib.project.controller.form.LibaddrForm;
import com.zhz.lib.project.service.TypeService;
import com.zhz.project.common.util.ibatispage.IbatisPage;
import com.zhz.project.common.util.zhzutil.ZhzBeanUtils;
import com.zhz.project.common.util.zhzutil.ZhzHttpRequestUtil;

/**
 * @author LiWei <a href="mailto:liwei2672@gmail.com">liwei2672@gmail.com</a>
 * @version $Id: LibaddrController.java, v 0.1 2010-12-12 下午01:22:43 liwei Exp $
 */
@Controller
@RequestMapping("/libaddr.htm")
public class LibaddrController {
    @Autowired
    private TypeService   typeService;
    @Autowired
    private IbatisPage    ibatisPage;
    private static String pageSql  = "selectAllLibaddrByPage";
    private static String countSql = "selectAllLibaddrCount";

    /**
     * 馆内通讯录列表(Ibatis)
     * 
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, params = "action=page")
    public String getIbatisListPost(ModelMap model, LibaddrForm libaddrForm) {
        return page(model, libaddrForm);
    }

    /**
     * 馆内通讯录列表(Ibatis)
     * 
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, params = "action=page")
    public String getIbatisListGet(ModelMap model, LibaddrForm libaddrForm) {
        return page(model, libaddrForm);
    }

    private String page(ModelMap model, LibaddrForm libaddrForm) {

        ZhzHttpRequestUtil.writeMapToModelMap(model, ibatisPage.getPage(ZhzBeanUtils
            .describe(libaddrForm), countSql, pageSql));
        typeService.setToModelMap(model);
        return "libaddrlist";
    }

}
